﻿/// 流程节点数据的保存
function FlowData(flowdata) {
  this.FlowID = undefined
  this.SysParam = {}
  this.VariableList = []
  this.callfun=function () {

  }
  this.VariableList.push({
    name: 'Header_formSubTitle',
    title: '@主题',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_formNumber',
    title: '@编号',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_CreateUserName',
    title: '@创建人名称',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_CreateUserID',
    title: '@创建人',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_CreateDepName',
    title: '@创建部门名称',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_CreateDepID',
    title: '@创建部门',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_Document_Status',
    title: '@流程状态',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_applicantUserShow',
    title: '@申请人名称',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_applicantUserID',
    title: '@申请人',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_applicantUser_DepName',
    title: '@申请人部门名称',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_applicantUser_DepID',
    title: '@申请人部门',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'Header_CreateDate',
    title: '@提交时间',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: '@Action',
    title: '@审批动作',
    Children: [],
    IsDetail: false
  })
  this.VariableList.push({
    name: 'hidPrevActName',
    title: '@上一节点名称',
    Children: [],
    IsDetail: false
  })
  this.SysParam.VariableList = JSON.parse(JSON.stringify(this.VariableList))
  this.FromControl = []
  this.FromControl.push({
    name: 'Header_formSubTitle',
    title: '@主题',
    Children: [],
    IsDetail: false
  })
  this.FromControl.push({
    name: 'Header_formNumber',
    title: '@编号',
    Children: [],
    IsDetail: false
  })
  this.FromControl.push({
    name: 'Header_CreateUserName',
    title: '@创建人名称',
    Children: [],
    IsDetail: false
  })
  this.FromControl.push({
    name: 'Header_CreateDepName',
    title: '@创建部门名称',
    Children: [],
    IsDetail: false
  })
  this.FromControl.push({
    name: 'Header_Document_Status',
    title: '@流程状态',
    Children: [],
    IsDetail: false
  })
  this.FromControl.push({
    name: 'Header_applicantUserShow',
    title: '@申请人名称',
    Children: [],
    IsDetail: false
  })
  this.FromControl.push({
    name: 'Header_applicantUser_DepName',
    title: '@申请人部门名称',
    Children: [],
    IsDetail: false
  })
  this.FromControl.push({
    name: 'Header_CreateDate',
    title: '@提交时间',
    Children: [],
    IsDetail: false
  })
  // this.SysParam.FromControl=JSON.parse(JSON.stringify(this.FromControl));
  this.SysParam.Node = {}
  this.Data = flowdata == undefined ? this.CreateInit() : flowdata
  this.selectedNode = null
  const $this = this
  flowObj.CreateNodeEvent = function(node) {
    $this.SysParam.Node[$(node).attr('id')] = $(
      '#Text' + $(node).attr('id')
    ).text()
  }
  flowObj.DelNodeEvent = function(node) {
    /// 删除节点或者连线
    function delLineData(line) {
      const startNodeId = line.getAttribute('startNode')
      const endNodeId = line.getAttribute('endNode')
      const nodedata = $this.Data.Node[startNodeId]
      for (let idex = 0; idex < nodedata.Routing.length; idex++) {
        const routingitem = nodedata.Routing[idex]
        if (routingitem.nodeID == endNodeId) {
          nodedata.Routing.remove(routingitem)
          return
        }
      }
    }
    if ($(node).prop('tagName') == 'polyline') {
      /// 如果删除的是线条 需要将对应路由删除掉
      delLineData(node)
    } else {
      $("[endNode='" + $(node).attr('id') + "']").each(function() {
        delLineData(this)
      })
      delete $this.SysParam.Node[$(node).attr('id')]
      delete $this.Data.Node[$(node).attr('id')]
    }
  }
  flowObj.CreateLineEvent = function(line) {
    const startNodeId = line.getAttribute('startNode')
    const endNodeId = line.getAttribute('endNode')
    const nodedata = $this.GetNodeInfo(startNodeId)
    const item = {}
    item.ruleName = '@审批动作=审批'
    item.nodeName = $this.SysParam.Node[endNodeId]
    item.nodeID = endNodeId
    item.routingList = []
    if (startNodeId != 'F_Start') {
      item.routingList.push({
        variableName: '@审批动作',
        variable: '@Action',
        operatorName: '等于',
        operator: '=',
        value: '审批',
        description: ''
      })
    } else {
      item.routingList.push({
        variableName: '@审批动作',
        variable: '@Action',
        operatorName: '等于',
        operator: '=',
        value: '发起',
        description: ''
      })
    }
    item.expressionList = []
    item.expressionList.push({
      operator: 'and',
      Where: 1,
      operator2: 'and',
      toWhere: 1
    })
    nodedata.Routing.push(item)
    $('#resLeftFilterWrap').show()
    if ($('#flowNodeInfo').is(':hidden')) {
      $('#flowNodeInfo').show()
      $('#flowBaseInfo').hide()
      $('#cheackErrorMsg').hide()
    }
    $this.SelectNode(startNodeId, 'routing') /// 然后选中
  }
  /// 连线改变事件
  flowObj.ChangedLineEvent = function(line, endnodeID) {
    const startNodeId = line.getAttribute('startNode')
    const endNodeId = line.getAttribute('endNode')
    const nodedata = $this.GetNodeInfo(startNodeId)
    for (let idex = 0; idex < nodedata.Routing.length; idex++) {
      const routingitem = nodedata.Routing[idex]
      if (routingitem.nodeID == endNodeId) {
        routingitem.nodeName = $this.SysParam.Node[endnodeID]
        routingitem.nodeID = endnodeID
        return
      }
    }
  }
  /// 选中线条事件
  flowObj.SelectLineEvent = function(line) {
    const startNodeId = line.getAttribute('startNode')
    const endNodeId = line.getAttribute('endNode')
    $('#resLeftFilterWrap').show()
    if ($('#flowNodeInfo').is(':hidden')) {
      $('#flowNodeInfo').show()
      $('#flowBaseInfo').hide()
      $('#cheackErrorMsg').hide()
    }
    $this.SelectNode(startNodeId, 'routing') /// 然后选中
  }
  $('[nodetype]').each(function() {
    if ($(this).attr('nodetype') != 'Line') {
      if ($(this).attr('id') == 'F_End') {
        $this.SysParam.Node[$(this).attr('id')] = '结束'
      } else {
        $this.SysParam.Node[$(this).attr('id')] = $(
          '#Text' + $(this).attr('id')
        ).text()
      }
    }
  })
}
/// 初始化
FlowData.prototype.Init = function() {
  const $this = this
  const childtr = {
    name: 'childcontrl',
    props: ['childitem', 'datapermission', 'needref'],
    template: ` <div class="tr" >
        <div class="td">{{ childitemdata.title }}</div>
        <div class="td"> <div class="input-group">
                                                        <span class="input-group-btn" style="padding: 0 0px !important;"
                                                              type="checkboxlist"
                                                              @click="datapermissiondata.Read=!datapermissiondata.Read"><a
                                                                class="footable-ickeck checkbox-ickeck"
                                                                v-bind:class="{checked:datapermissiondata!==undefined&& datapermissiondata.Read }"
                                                                value="1" title="启用"><label></label></a></span>
                                                    </div></div>
        <div class="td">  <div class="input-group">
                                                        <span class="input-group-btn" style="padding: 0 0px !important;"
                                                              type="checkboxlist"
                                                              @click="datapermissiondata.Write=!datapermissiondata.Write"><a
                                                                class="footable-ickeck checkbox-ickeck"
                                                                v-bind:class="{checked:datapermissiondata!==undefined&& datapermissiondata.Write }"
                                                                title="启用"><label></label></a></span>
                                                    </div></div>
        <div class="td">  <div class="input-group">
                                                        <span class="input-group-btn" style="padding: 0 0px !important;"
                                                              type="checkboxlist"
                                                              @click="datapermissiondata.Required=!datapermissiondata.Required"><a
                                                                class="footable-ickeck checkbox-ickeck"
                                                                v-bind:class="{checked:datapermissiondata!==undefined&& datapermissiondata.Required }"
                                                                value="1" title="启用"><label></label></a></span>
                                                    </div></div>
        <div class="clearfloat"></div>
         <template class="tr" v-for="childitem1 in childitemdata.Children" >
          <childcontrl :childitem="childitem1" :key="childitem1.name" :datapermission="datapermissiondata.Children[childitem1.name]"></childcontrl>
         </template>
      </div>`,
    data() {
      return {
        childitemdata: this.childitem,
        datapermissiondata: this.datapermission
      }
    },
    created() {
      if (this.datapermission === undefined) {
        // this.datapermission={Required:false,Read:false,Write:false}
        // if(this.childitem.Children!==undefined){
        //   this.datapermission["IsRow"]=true
        //   this.datapermission["IsDetail"]=false
        //   this.datapermission["IsOperation"]=false
        //   this.datapermission.Children={}
        //   this.childitem.Children.forEach(ee=>{
        //     this.datapermission.Children[ee.name]={Required:false,Read:false,Write:false}
        //   })
        // }
        // this.datapermissiondata=this.datapermission
        // this.$emit("update:datapermission",this.datapermissiondata)
      }
    }
  }
  Vue.component('childcontrl', childtr)
  new Vue({
    el: '#flowBaseInfo',
    data: $this.Data,
    methods: {
      /// 选表单
      selectFrom() {
        window.parent.postMessage({ funname: 'selectFrom' })
      },
      selectStartPerson() {
        window.parent.postMessage(
          { funname: 'selectStartPerson' }
        )
      },
      selectReadPerson() {
        window.parent.postMessage(
          { funname: 'selectReadPerson' }
        )
      }
    }
  })
}
/// 新建流程图 第一次初始化
FlowData.prototype.CreateInit = function() {
  const data = {}
  data.FromID = ''
  data.PageControlList = []
  data.FlowName = ''
  data.FlowCode = ''
  data.fromname = ''
  data.BusinessMoudle = 'wmp'
  data.BusinessModuleID = 'M' + DateFormat('yyyyMMddHHmmss')
  function DateFormat(fmt) {
    const $this = new Date()
    const o = {
      'M+': $this.getMonth() + 1, // 月份
      'd+': $this.getDate(), // 日
      'H+': $this.getHours(), // 小时
      'm+': $this.getMinutes(), // 分
      's+': $this.getSeconds(), // 秒
      'q+': Math.floor(($this.getMonth() + 3) / 3), // 季度
      S: $this.getMilliseconds() // 毫秒
    }
    if (/(y+)/.test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        String($this.getFullYear()).substr(4 - RegExp.$1.length)
      )
    for (const k in o) {
      if (new RegExp('(' + k + ')').test(fmt))
        fmt = fmt.replace(
          RegExp.$1,
          RegExp.$1.length == 1
            ? o[k]
            : ('00' + o[k]).substr(String(o[k]).length)
        )
    }
    return fmt
  }
  data.FlowType = 'HR'
  data.FlowTypeName = 'HR流程'
  data.FlowTypeList = []
  data.FlowTypeList.push({ FlowTypeCode: 'HR', FlowTypeName: 'HR流程' })
  data.FlowTypeList.push({ FlowTypeCode: '财务', FlowTypeName: '财务流程' })
  data.FlowTypeList.push({ FlowTypeCode: '营销', FlowTypeName: '营销流程' })
  data.FIsEnabledAlert = true /// 是否启动催办提醒
  data.FMessageType = 'email;rtx;todo' /// 提醒方式
  data.FStartType = '' /// 发起人类型
  data.FStartPerson = '' /// 发起人
  data.FStartPersonName = '' /// 发起人显示名称
  data.FReadPersonName = '' // 可阅读人显示名称
  data.FReadPerson = '' // 可阅读人
  data.FIsAlertStarter = true /// 结束通知申请人
  data.FIsCopyStart = true /// 可复制草稿
  data.FRemark = '' /// 备注信息
  data.Head = {}
  data.Head.Header_formSubTitle = true
  data.Head.Header_formNumber = true
  data.Head.Header_CreateUserName = true
  data.Head.Header_CreateDepName = true
  data.Head.Header_Document_Status = true
  data.Head.Header_applicantUserShow = true
  data.Head.Header_applicantUser_DepName = true
  data.Head.Header_CreateDate = true
  data.Head.Header_applicantUserIDShow = false
  data.Head.Header_applicantUser_EMail = false
  data.Head.Header_applicantUser_Phone = false
  data.EmailConfig = []
  data.VariableList = this.SysParam.VariableList
  data.FromControl = JSON.parse(JSON.stringify(this.FromControl))
  data.Node = {}
  data.Node.F_Start = {}
  data.Node.F_Start.FActChartID = 'F_Start'
  data.Node.F_Start.FNodeName = $('#TextF_Start').text()
  data.Node.F_Start.FIsEmail = true
  data.Node.F_Start.FIsRejectHistory = false
  data.Node.F_Start.FIsRejectEmail = false
  data.Node.F_Start.FIsContinuousBy = false
  data.Node.F_Start.FIsNotContinuousBy = false
  data.Node.F_Start.FHandleType = '1'
  data.Node.F_Start.FHandleTypeName = '节点审批处理'
  data.Node.F_Start.FHandleCountersignType = '1' /// 会签规则
  data.Node.F_Start.FHandleCountersignTypeName = '所有审批通过' /// 会签规则
  data.Node.F_Start.FCounterSignType = '1' /// 会签模式
  data.Node.F_Start.FApprovalType = '1'
  data.Node.F_Start.FApproverName = ''
  data.Node.F_Start.FApprover = ''
  data.Node.F_Start.FCCPerson = ''
  data.Node.F_Start.FApprovalObj = '' /// 固定人员
  data.Node.F_Start.FAlertFrequency = '' /// 提醒天/次
  data.Node.F_Start.FAlertDays = '' // 工作日
  data.Node.F_Start.OperatePermission = []
  data.Node.F_Start.OperatePermission.push({
    OperateName: '暂存',
    OperateType: 'Save',
    IsVisible: true,
    ShowName: '暂存'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '提交',
    OperateType: 'Start',
    IsVisible: true,
    ShowName: '提交'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '驳回',
    OperateType: 'Sendback',
    IsVisible: false,
    ShowName: '驳回'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '审批',
    OperateType: 'Approval',
    IsVisible: false,
    ShowName: '审批'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '废弃(申请人)',
    OperateType: 'Abandon',
    IsVisible: false,
    ShowName: '废弃'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '废弃(审批人)',
    OperateType: 'Abandon_App',
    IsVisible: false,
    ShowName: '废弃'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '撤销(申请人)',
    OperateType: 'Repeal',
    IsVisible: false,
    ShowName: '撤销'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '撤销(审批人)',
    OperateType: 'Repeal_App',
    IsVisible: false,
    ShowName: '撤销'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '沟通',
    OperateType: 'StartQuery',
    IsVisible: false,
    ShowName: '沟通'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '催办',
    OperateType: 'HastenWork',
    IsVisible: false,
    ShowName: '催办'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '抄送',
    OperateType: 'CopySend',
    IsVisible: false,
    ShowName: '抄送'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '转办',
    OperateType: 'Tranfer',
    IsVisible: false,
    ShowName: '转办'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '打印',
    OperateType: 'Print',
    IsVisible: true,
    ShowName: '打印'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '扩展按钮1',
    OperateType: 'Extend1',
    IsVisible: false,
    ShowName: '扩展按钮1'
  })
  data.Node.F_Start.OperatePermission.push({
    OperateName: '扩展按钮2',
    OperateType: 'Extend2',
    IsVisible: false,
    ShowName: '扩展按钮2'
  })
  data.Node.F_Start.AttachmentPermission = []
  data.Node.F_Start.AttachmentPermission.push({
    OperateName: '下载',
    OperateType: 'CanDownLoad',
    IsVisible: true
  })
  data.Node.F_Start.AttachmentPermission.push({
    OperateName: '可删除(可删除所有上传的附件)',
    OperateType: 'RemoveAll',
    IsVisible: false
  })
  data.Node.F_Start.AttachmentPermission.push({
    OperateName: '必填',
    OperateType: 'Required',
    IsVisible: false
  })
  data.Node.F_Start.AttachmentPermission.push({
    OperateName: '可删除(只能删除自己上传的附件)',
    OperateType: 'RemoveSelf',
    IsVisible: false
  })
  data.Node.F_Start.AttachmentPermission.push({
    OperateName: '可上传',
    OperateType: 'CanUpload',
    IsVisible: false
  })
  data.Node.F_Start.DataPermission = {}
  data.Node.F_End = {}
  data.Node.F_Start.Routing = []
  return data
}
/// 根据环节ID获取环节信息
FlowData.prototype.GetNodeInfo = function(nodeId) {
  if (this.Data.Node[nodeId] == undefined) {
    var node = {}
    node.FActChartID = nodeId /// 节点对应流程图节点的ID
    node.FNodeName = $('#Text' + nodeId).text() /// 节点名称
    node.FIsEmail = true /// 是否邮件通知
    node.FIsRejectHistory = false /// 是否可驳回历史
    node.FIsRejectEmail = false /// /是否发送驳回邮件
    node.FIsContinuousBy = false /// 是否连续跳过
    node.FIsNotContinuousBy = false /// 是否非连续跳过
    node.FHandleType = '1' /// 处理方式 单人处理 和会签处理两种模式
    node.FHandleTypeName = '节点审批处理'
    node.FHandleCountersignType = '1' /// 会签情况下 一人审批通过就通过，所有人审批通过，按照审批人顺序审批通过，半数审批通过就通过
    node.FHandleCountersignTypeName = '所有审批通过'
    node.FCounterSignType = '1'
    node.FApprovalType = '1' /// 审批人类型 1审批人，2审批角色，3审批线 4业务控件
    node.FApproverName = '' /// 审批人名称
    node.FApprover = '' /// 审批人ID
    node.FCCPerson = '' /// 抄送人
    node.FApprovalObj = '' /// 固定人员
    node.FAlertFrequency = '' /// 提醒天/次
    node.FAlertDays = '' // 工作日
    node.OperatePermission = []
    node.OperatePermission.push({
      OperateName: '暂存',
      OperateType: 'Save',
      IsVisible: true,
      ShowName: '暂存'
    })
    node.OperatePermission.push({
      OperateName: '提交',
      OperateType: 'Start',
      IsVisible: false,
      ShowName: '提交'
    })
    node.OperatePermission.push({
      OperateName: '驳回',
      OperateType: 'Sendback',
      IsVisible: true,
      ShowName: '驳回'
    })
    node.OperatePermission.push({
      OperateName: '审批',
      OperateType: 'Approval',
      IsVisible: true,
      ShowName: '审批'
    })
    node.OperatePermission.push({
      OperateName: '废弃(申请人)',
      OperateType: 'Abandon',
      IsVisible: false,
      ShowName: '废弃'
    })
    node.OperatePermission.push({
      OperateName: '废弃(审批人)',
      OperateType: 'Abandon_App',
      IsVisible: false,
      ShowName: '废弃'
    })
    node.OperatePermission.push({
      OperateName: '撤销(申请人)',
      OperateType: 'Repeal',
      IsVisible: false,
      ShowName: '撤销'
    })
    node.OperatePermission.push({
      OperateName: '撤销(审批人)',
      OperateType: 'Repeal_App',
      IsVisible: false,
      ShowName: '撤销'
    })
    node.OperatePermission.push({
      OperateName: '沟通',
      OperateType: 'StartQuery',
      IsVisible: true,
      ShowName: '沟通'
    })
    node.OperatePermission.push({
      OperateName: '催办',
      OperateType: 'HastenWork',
      IsVisible: false,
      ShowName: '催办'
    })
    node.OperatePermission.push({
      OperateName: '抄送',
      OperateType: 'CopySend',
      IsVisible: true,
      ShowName: '抄送'
    })
    node.OperatePermission.push({
      OperateName: '转办',
      OperateType: 'Tranfer',
      IsVisible: true,
      ShowName: '转办'
    })
    node.OperatePermission.push({
      OperateName: '打印',
      OperateType: 'Print',
      IsVisible: true,
      ShowName: '打印'
    })
    node.OperatePermission.push({
      OperateName: '扩展按钮1',
      OperateType: 'Extend1',
      IsVisible: false,
      ShowName: '扩展按钮1'
    })
    node.OperatePermission.push({
      OperateName: '扩展按钮2',
      OperateType: 'Extend2',
      IsVisible: false,
      ShowName: '扩展按钮2'
    })
    node.AttachmentPermission = []
    node.AttachmentPermission.push({
      OperateName: '下载',
      OperateType: 'CanDownLoad',
      IsVisible: true
    })
    node.AttachmentPermission.push({
      OperateName: '可删除(可删除所有上传的附件)',
      OperateType: 'RemoveAll',
      IsVisible: false
    })
    node.AttachmentPermission.push({
      OperateName: '必填',
      OperateType: 'Required',
      IsVisible: false
    })
    node.AttachmentPermission.push({
      OperateName: '可删除(只能删除自己上传的附件)',
      OperateType: 'RemoveSelf',
      IsVisible: false
    })
    node.AttachmentPermission.push({
      OperateName: '可上传',
      OperateType: 'CanUpload',
      IsVisible: false
    })
    node.DataPermission = {}
    this.Data.FromControl.forEach(ee => {
      if (node.DataPermission[ee.name] == undefined) {
        node.DataPermission[ee.name] = {
          Required: false,
          Read: false,
          Write: false,
          Children:{},
          IsRow:true,
          IsDetail:false,
          IsOperation:false
        }
      }
      if (ee.Children != undefined) {
        initDataPermission(node.DataPermission[ee.name], ee.Children)
      }
    })

    node.Routing = []
    this.Data.Node[nodeId] = node
  } else {
    var node = this.Data.Node[nodeId]
    this.Data.FromControl.forEach(ee => {
      if (node.DataPermission[ee.name] == undefined) {
        node.DataPermission[ee.name] = {
          Required: false,
          Read: false,
          Write: false,
          Children:{},
          IsRow:true,
          IsDetail:false,
          IsOperation:false
        }
      }
      if (ee.Children != undefined) {
        initDataPermission(node.DataPermission[ee.name], ee.Children)
      }
    })
  }
  function initDataPermission(dataPermission, list) {
    list.forEach(ee => {
      if (dataPermission.Children[ee.name] == undefined) {
        dataPermission.Children[ee.name] = {
          Required: false,
          Read: false,
          Write: false,
          Children:{},
          IsRow:true,
          IsDetail:false,
          IsOperation:false
        }
      }
      if (ee.Children != undefined) {
        initDataPermission(dataPermission.Children[ee.name], ee.Children)
      }
    })
  }
  return this.Data.Node[nodeId]
}
/// 选中节点
FlowData.prototype.SelectNode = function(newNodeId, selTab) {
  if (newNodeId == 'F_End') {
    $('#flowNodeInfo').text('流程结束节点不用设置！')
    return
  }
  this.selectedNode = this.GetNodeInfo(newNodeId)
  $('#flowNodeInfo').empty()
  $('#flowNodeInfo').append($('#flowNode-tmpl-tfs').html())
  function newid() {
    return (
      'f' +
      Number(
        Math.random()
          .toString()
          .substr(3, length) + Date.now()
      ).toString(36)
    )
  }
  const $this = this
  new Vue({
    el: '#flowNodeInfo',
    data: {
      node: this.selectedNode,
      checkRead: false,
      checkWrite: false,
      checkRequired: false
    },
    methods: {
      checkReadAll() {
        /// 全选可阅
        this.checkRead = !this.checkRead
        checkAll(this.node.DataPermission, this.checkRead)
        function checkAll(list, checkRequired) {
          for (const key in list) {
            list[key].Read = checkRequired
            checkAll(list[key].Children, checkRequired)
          }
        }
        this.$forceUpdate()
      },
      checkWriteAll() {
        /// 全选可写
        this.checkWrite = !this.checkWrite
        checkAll(this.node.DataPermission, this.checkWrite)
        function checkAll(list, checkRequired) {
          for (const key in list) {
            list[key].Write = checkRequired
            checkAll(list[key].Children, checkRequired)
          }
        }
        this.$forceUpdate()
      },
      checkRequiredAll() {
        /// 全选必填
        this.checkRequired = !this.checkRequired
        checkAll(this.node.DataPermission, this.checkRequired)
        function checkAll(list, checkRequired) {
          for (const key in list) {
            list[key].Required = checkRequired
            checkAll(list[key].Children, checkRequired)
          }
        }
        this.$forceUpdate()
      },
      checkReadItem(control, parentcontrolkey) {
        control.Read = !control.Read
        for (var item in control.Children) {
          control.Children[item].Read = control.Read
        }
        const parentcontrol = this.node.DataPermission[parentcontrolkey]
        if (parentcontrol != undefined) {
          let isRead = false
          for (var item in parentcontrol.Children) {
            if (parentcontrol.Children[item].Read) {
              isRead = true
              continue
            }
          }
          parentcontrol.Read = isRead
        }
        this.$forceUpdate()
      },
      checkWriteItem(control, parentcontrol) {
        control.Write = !control.Write
        for (const item in control.Children) {
          control.Children[item].Write = control.Write
        }
        if (parentcontrol != undefined) {
          parentcontrol.Write = control.Write
        }
        this.$forceUpdate()
      },
      checkOperationItem(control) {
        control.IsOperation = !control.IsOperation
        this.$forceUpdate()
      },
      checkRowItem(control) {
        control.IsRow = !control.IsRow
        this.$forceUpdate()
      },
      checkRequiredItem(control, parentcontrol) {
        control.Required = !control.Required
        for (const item in control.Children) {
          control.Children[item].Required = control.Required
        }
        if (parentcontrol != undefined) {
          parentcontrol.Required = control.Required
        }
        this.$forceUpdate()
      },
      ShowHideChild(control) {
        if (control.Children.length == 0) {
          return
        }
        control.IsShow = !control.IsShow
        this.$forceUpdate()
      },
      getControl(ParentKey, childKey) {
        if (typeof this.node.DataPermission[ParentKey] === 'undefined') {
          $this.selectedNode.DataPermission[ParentKey] = {
            Read: false,
            Write: false,
            Required: false,
            Children: {},
            IsShow: false,
            IsOperation: false,
            IsRow: false
          }
        }
        if (childKey != '') {
          if (
            typeof this.node.DataPermission[ParentKey].Children[childKey] ===
            'undefined'
          ) {
            this.node.DataPermission[ParentKey].Children[childKey] = {
              Read: false,
              Write: false,
              Required: false,
              Children: {}
            }
          }
          return this.node.DataPermission[ParentKey].Children[childKey]
        }
        return $this.selectedNode.DataPermission[ParentKey]
      },
      editRouting(item, editnodeId) {
        const $this = this
        layer.open({
          type: 1,
          title: '<span>路由编辑</span>',
          content: $('#RoutingTemp').html(),
          anim: 'up',
          success(layero, index) {
            routingdialog = $(layero)
            dialogResize(routingdialog, 800, 400)
            const contentID = newid()
            routingdialog.find('.layui-content').attr('id', contentID)
            let IsAdd = false
            let oldNodeID
            if (item == undefined) {
              item = {}
              for (const key in flowdataObj.SysParam.Node) {
                if (!(key == 'F_Start' || key == editnodeId)) {
                  item.nodeName = flowdataObj.SysParam.Node[key]
                  item.nodeID = key
                  break
                }
              }
              item.routingList = []
              item.routingList.push({
                variableName: '@审批',
                variable: '@Action',
                operatorName: '等于',
                operator: '=',
                value: '',
                description: ''
              })
              item.expressionList = []
              item.expressionList.push({
                operator: 'and',
                Where: 1,
                operator2: 'and',
                toWhere: 1
              })
              IsAdd = true
            } else {
              oldNodeID = item.nodeID
              item.nodeName = flowdataObj.SysParam.Node[item.nodeID]
            }
            new Vue({
              el: '#' + contentID,
              data: item,
              methods: {
                addrouting() {
                  this.routingList.push({
                    variableName: '@审批',
                    variable: '@Action',
                    operatorName: '等于',
                    operator: '=',
                    value: '',
                    description: ''
                  })
                },
                addexpression() {
                  this.expressionList.push({
                    operator: 'and',
                    Where: 1,
                    operator2: 'and',
                    toWhere: 1
                  })
                },
                deleterouting(item) {
                  this.$delete(this.routingList, item)
                },
                deleteexpression(item) {
                  this.$delete(this.expressionList, item)
                },
                IsShow(nodeId) {
                  if (nodeId == 'F_Start' || nodeId == editnodeId) {
                    return false
                  }
                  return true
                }
              }
            })
            /// 保存方法
            routingdialog.find('#butSave').click(function() {
              if (item.nodeID == '') {
                window.parent.postMessage(
                  { error: 'success', msg: '到达节点不能为空！' }
                )
              }
              const routingitemNames = []
              for (var idex = 0; idex < item.routingList.length; idex++) {
                var routingItem = item.routingList[idex]
                if (routingItem.variable == '') {
                  window.parent.postMessage(
                    { error: 'success', msg: '输出规则变量不能为空！' }
                  )
                  return
                }
                if (routingItem.operator == '') {
                  window.parent.postMessage(
                    { error: 'success', msg: '输出规则运算符不能为空！' }
                  )
                  return
                }
                if (routingItem.value == '') {
                  window.parent.postMessage(
                    { error: 'success', msg: '输出规则值不能为空！' }
                  )
                  return
                }
                routingitemNames.push(
                  routingItem.variableName +
                    routingItem.operator +
                    routingItem.value
                )
              }
              let routingName = ''
              for (var idex = 0; idex < item.expressionList.length; idex++) {
                const expressionItem = item.expressionList[idex]
                if (expressionItem.operator2 == '') {
                  window.parent.postMessage(
                    { error: 'success', msg: '表达式逻辑符不能为空！' }
                  )
                  return
                }
                if (routingItem.operator == '') {
                  window.parent.postMessage(
                    { error: 'success', msg: '表达式逻辑符不能为空！' }
                  )
                  return
                }
                if (idex == 0) {
                  if (
                    expressionItem.Where == expressionItem.toWhere &&
                    expressionItem.operator2 == 'and'
                  ) {
                    routingName =
                      routingitemNames[expressionItem.Where - 1] + ' '
                  } else {
                    routingName =
                      '(' +
                      routingitemNames[expressionItem.Where - 1] +
                      ' ' +
                      expressionItem.operator2 +
                      ' ' +
                      routingitemNames[expressionItem.toWhere - 1] +
                      ') '
                  }
                } else if (
                  expressionItem.Where == expressionItem.toWhere &&
                  expressionItem.operator2 == 'and'
                ) {
                  routingName =
                    routingName +
                    expressionItem.operator +
                    ' ' +
                    routingitemNames[expressionItem.Where - 1] +
                    ' '
                } else {
                  routingName =
                    routingName +
                    expressionItem.operator +
                    '(' +
                    routingitemNames[expressionItem.Where - 1] +
                    ' ' +
                    expressionItem.operator2 +
                    ' ' +
                    routingitemNames[expressionItem.toWhere - 1] +
                    ')'
                }
              }
              item.ruleName = routingName
              if (IsAdd) {
                $this.node.Routing.push(item)
                flowObj.CreateLine(editnodeId, item.nodeID)
              } else {
                flowObj.ChangedLine(editnodeId, oldNodeID, item.nodeID)
              }
              layer.close(routingdialog.attr('Index'))
            })
            /// 关闭方法
            routingdialog.find('#butclose').click(function() {
              layer.close(routingdialog.attr('Index'))
            })
          }
        })
      },
      delRouting(item, editnodeId) {
        flowObj.DelLine(editnodeId, item.nodeID)
        this.node.Routing.remove(item)
      },
      selectApprover() {
        window.parent.postMessage(
          { funname: 'selectApprover' }
        )
      }
    }
  })
  if (selTab != undefined) {
    $('#lik_' + selTab).click()
  }
  if (newNodeId == 'F_Start') {
    $('#txt_FNodeName').attr('disabled', 'disabled')
  }

  if ($('#txt_FNodeId').val() != undefined && $('#txt_FNodeId').val() != '') {
    $('#txt_FNodeName').on('input propertychange', function() {
      $('#Text' + $('#txt_FNodeId').val()).text($(this).val())
      flowdataObj.SysParam.Node[$('#txt_FNodeId').val()] = $(this).val()
      $("[endNode='" + $('#txt_FNodeId').val() + "']").each(function() {
        const startNodeId = this.getAttribute('startNode')
        const endNodeId = this.getAttribute('endNode')
        const nodedata = flowdataObj.Data.Node[startNodeId]
        for (let idex = 0; idex < nodedata.Routing.length; idex++) {
          const routingitem = nodedata.Routing[idex]
          if (routingitem.nodeID == endNodeId) {
            routingitem.nodeName =
              flowdataObj.SysParam.Node[$('#txt_FNodeId').val()]
          }
        }
      })
    })
  }
}
/// 保存流程模板
FlowData.prototype.SaveFlowData = function() {
  if (!this.CheackData(false)) {
    return
  }
  const param = {
    flowJson: JSON.stringify(this.Data),
    flowdraw: JSON.stringify(flowObj.SaveDrawJson()),
    flowID: ''
  }
  if (this.FlowID != undefined && this.FlowID != null && this.FlowID != '') {
    param.flowID = this.FlowID
  }
  const $this = this
   this.callfun=function(d){
       if (d.success) {
         const data = JSON.parse(d.data)
         $this.FlowID = data.flowID
         $this.Data = JSON.parse(data.flowJson)
         $('#txtFlowCode').attr('disabled', 'disabled')
         window.parent.postMessage(
           { funname: 'success', msg: '保存成功！' }
         )
       }
   }
  window.parent.postMessage(
    { funname: 'SaveFlowData', param: param
    }
  )
}
FlowData.prototype.StartFlow = function() {
  if (!this.CheackData(false)) {
    return
  }
  const param = {
    flowJson: JSON.stringify(this.Data),
    flowdraw: JSON.stringify(flowObj.SaveDrawJson()),
    flowID: ''
  }
  if (this.FlowID != undefined && this.FlowID != null && this.FlowID != '') {
    param.flowID = this.FlowID
  }
  const $this = this
   this.callfun=function(d){
     if (d.success) {
       const data = JSON.parse(d.data)
       $this.FlowID = data.flowID
       $this.Data = JSON.parse(data.flowJson)
       $('#txtFlowCode').attr('disabled', 'disabled')
       $('#btnSave').hide()
       $('#btnCheck').hide()
       $('#btnIssue').hide()
       $('#btnStop').show()

       window.parent.postMessage(
         { funname: 'success', msg: '保存成功！' }
       )
     } else {
       window.parent.postMessage(
         { funname: 'error', msg: '保存成功！' }
       )
     }
 }
  window.parent.postMessage(
    { funname: 'DesignStartFlow', param: param
    }
  )
}
FlowData.prototype.StopFlow = function() {
  if (this.FlowID != undefined && this.FlowID != null && this.FlowID != '') {
    // AJAXAPI('/Process/StopFlow/' + this.FlowID, {}, function(d) {
    //   if (d.success) {
    //     /// ShowTip(d.msg);
    //     window.location.href = '/Flow/flowdesign?ProcessId=' + d.data
    //   } else {
    //     window.parent.postMessage(
    //       { funname: 'error', msg: d.msg }
    //     )
    //   }
    // })
    this.callfun=function(res){
      if (res.success) {
        window.location.href = '/Flow/flowdesign?ProcessId=' + res.data
      }else{
        window.parent.postMessage(
          { error: 'success', msg: res.msg }
        )
      }
    }
    window.parent.postMessage(
      { funname: 'StopFlow', param: this.FlowID
      }
    )
  }
}
FlowData.prototype.SaveAs = function() {
 var $this=this
  layer.open({
    type: 1,
    title: '<span>页面另存为</span>',
    content: $('#SaveAs').html(),
    anim: 'up',
    success(layero, index) {
      SaveAsdialog = $(layero)
      dialogResize(SaveAsdialog, 800, 400)
      SaveAsdialog.find('.save').click(function() {
        const param = {
          processname: SaveAsdialog.find('#txtprocessname').val(),
          processcode: SaveAsdialog.find('#txtprocesscode').val(),
          processid: Id
        }
        if (param.processname == '') {
          window.parent.postMessage(
            { error: 'success', msg: '流程名称不能为空！' }
          )
          return
        }
        if (param.processcode == '') {
          window.parent.postMessage(
            { error: 'success', msg: '流程编码不能为空！' }
          )
          return
        }
        // AJAXAPI('/Process/SaveAsFlow', param, function(d) {
        //   if (d.success) {
        //     layer.close(SaveAsdialog.attr('Index'))
        //   } else {
        //     window.parent.postMessage(
        //       { error: 'success', msg: d.msg }
        //     )
        //     return false
        //   }
        // })
        $this.callfun=function(res){
          if (res.success) {
            layer.close(SaveAsdialog.attr('Index'))
          }else{
            window.parent.postMessage(
              { error: 'success', msg: res.msg }
            )
          }
        }
        window.parent.postMessage(
          { funname: 'SaveAsFlow', param: param}     )
      })
      /// 关闭方法
      SaveAsdialog.find('#butclose').click(function() {
        layer.close(SaveAsdialog.attr('Index'))
      })
    }
  })
}
/// 检查数据是否有效
FlowData.prototype.CheackData = function(IsTips) {
  $('.starterror').removeClass('starterror')
  $('.nodeerror').removeClass('nodeerror')
  const msgarry = []
  if ($("[endNode='F_End']").length == 0) {
    msgarry.push('未有路由走向结束！')
  }
  if ($("[startNode='F_Start']").length == 0) {
    msgarry.push('发起节点未配置路由！')
    $('.startnode').addClass('starterror')
  }
  if (this.Data.FromID == undefined || this.Data.FromID == '') {
    msgarry.push('流程表单未创建！')
  }
  if (this.Data.FlowName == undefined || this.Data.FlowName == '') {
    msgarry.push('流程名称不能为空！')
  }
  if (this.Data.FlowCode == undefined || this.Data.FlowCode == '') {
    msgarry.push('流程编码不能为空！')
  }
  if (this.Data.FlowType == undefined || this.Data.FlowType == '') {
    msgarry.push('流程类型不能为空！')
  }
  if (msgarry.length == 0) {
    if (this.FlowID == undefined || this.FlowID == '') {
      // AJAXAPI(
      //   '/Process/CheackProcesscode/' + this.Data.FlowCode,
      //   {},
      //   function(d) {
      //     if (!d.success) {
      //       msgarry.push('流程编码已存在，不能重复！')
      //     }
      //   },
      //   undefined,
      //   undefined,
      //   false
      // )
      this.callfun=function(res){
        if (!d.success) {
                msgarry.push('流程编码已存在，不能重复！')
              }
      }
      window.parent.postMessage(
        { funname: 'CheackProcesscode', param: this.Data.FlowCode
          }
      )
    }
    const $this = this
    const nodeList = $("[nodetype='Node']")
    for (let idex = 0; idex < nodeList.length; idex++) {
      const node = nodeList[idex]
      let nodetext = this.SysParam.Node[$(node).attr('id')]
      let IsError = false
      if (nodetext == '') {
        msgarry.push('节点名称不能为空！')
        IsError = true
      }
      const nodeidstr = $(node).attr('id')
      nodetext = nodetext + '(' + nodeidstr + ')'
      const nodedata = $this.GetNodeInfo($(node).attr('id'))
      if (nodedata.FNodeName == undefined || nodedata.FNodeName == '') {
        nodedata.FNodeName = nodetext
      }
      if (nodedata.FApprovalType == '1') {
        /// 审批对象不能为空
        if (nodedata.FApprovalObj == undefined || nodedata.FApprovalObj == '') {
          msgarry.push('【' + nodetext + '】审批对象固定角色未设置！')
          IsError = true
        }
      } else {
        /// 业务ID不能为空
        if (nodedata.FApprover == undefined || nodedata.FApprover == '') {
          msgarry.push('【' + nodetext + '】审批对象业务ID未设置！')
          IsError = true
        }
      }
      if (
        $("[startNode='" + $(node).attr('id') + "']").length == 0 ||
        nodedata.Routing.length == 0
      ) {
        msgarry.push('未有路由流出节点【' + nodetext + '】')
        IsError = true
      }
      /// /检查节点是否必填项
      if (IsError) {
        $(node)
          .find('.node')
          .addClass('nodeerror')
      }
    }
  }
  /// this.Data   检查流程基本配置必填项
  if (msgarry.length > 0) {
    $('#cheackErrorMsg')
      .find('.ibox-content')
      .empty()
    $('#errorMsg-tmpl')
      .tmpl({ rows: msgarry })
      .appendTo($('#cheackErrorMsg').find('.ibox-content'))
    $('#butShowError').show()
    ShowErrorPlane()

    return false
  }
  $('#butShowError').hide()
  if (IsTips == undefined && IsTips == true) {
    window.parent.postMessage(
      { funname: 'success', msg: '校验成功！' }
    )
  }

  return true
}
/// 编辑表单
FlowData.prototype.EditFrom = function() {
  window.parent.postMessage(
    { funname: 'EditFrom', fromid: this.Data.FromID }
  )
  // var $this = this;
  // parent.layer.open({
  //     type: 1,
  //     title: '<span></span>',
  //     content: $("#editTemp").html(),
  //     anim: 'up',
  //     success: function (layero, index) {
  //         editdialog = $(layero);
  //         window.parent.flowdataObj=flowdataObj;
  //         editdialog.find("#layer-title").replaceWith('<i class="fa fa-close winClose" style="content: normal; top:0px;right:0px;position: absolute;font-size: 24px;cursor: pointer;color:red "></i>');
  //         var url = "../SmartForm/FlowFormDesign.html?Index=" + editdialog.attr("Index");
  //         url = url + "&fromId=" + $this.Data.FromID;
  //         editdialog.find("#editFromTempiframe").attr("src", url).ready();
  //         editdialog.find(".winClose").click(function () {
  //             dialogConfirmBox("确定关闭吗？如果未保存，关闭后数据将会丢失,是否继续？", function (index) {
  //                 parent.layer.close(editdialog.attr("Index"));
  //                 parent.layer.close(index);
  //                 ///合并变量结果值
  //             }, function () {

  //             });
  //         });
  //     }
  // });
}
/// 更新流程表单变量
FlowData.prototype.UpdateVariable = function(frominfo, fromid) {
  this.Data.FromID = fromid
  this.Data.fromname = frominfo.formName
  $('#hidFromID').val(fromid)
  this.Data.VariableList = JSON.parse(JSON.stringify(this.VariableList))
  this.Data.FromControl = JSON.parse(JSON.stringify(this.FromControl))
  const $this = this
  frominfo.layoutitemlist[0].widgetForm.list.forEach(function(plane) {
    if (plane.type == 'gridPanel') {
      var control = {
        name: plane.model,
        title: plane.title,
        Children: [],
        IsDetail: false
      }
      $this.Data.FromControl.push(control)
      plane.columns[0].list.forEach(function(controlitem) {
        if (controlitem.type === 'partlayout') {
          // control.Children.push({
          //   name:controlitem.model,
          //   title: controlitem.name,
          //   Children: [],
          //   IsDetail: false
          // });
          controlitem.list.forEach(ee => {
            if (ee.options.filed !== undefined) {
              $this.Data.VariableList.push({
                name: ee.options.filed,
                title: ee.title
              })
            }
            control.Children.push({
              name: ee.model,
              title: ee.title,
              Children: [],
              IsDetail: false
            })
          })
        } else {
          control.Children.push({
            name: controlitem.model,
            title: controlitem.title,
            Children: [],
            IsDetail: false
          })
          if (controlitem.options.filed !== undefined) {
            $this.Data.VariableList.push({
              name: controlitem.options.filed,
              title: controlitem.title
            })
          }
        }
      })
    }
    if (plane.type == 'tabs' || plane.type == 'collapse') {
      var control = {
        name: plane.model,
        title: plane.name,
        Children: [],
        IsDetail: false
      }
      $this.Data.FromControl.push(control)

      plane.options.panelist.forEach(function(controlitem) {
        const childrenitem = {
          name: controlitem.name,
          title: controlitem.title,
          Children: [],
          IsDetail: false
        }
        control.Children.push(childrenitem)

        controlitem.columns[0].list.forEach(function(controlitem2) {
          if (controlitem2.type === 'partlayout') {
            controlitem2.list.forEach(ee => {
              if (ee.options.filed !== undefined) {
                $this.Data.VariableList.push({
                  name: ee.options.filed,
                  title: ee.title
                })
              }
              control.Children.push({
                name: ee.model,
                title: ee.title,
                Children: [],
                IsDetail: false
              })
            })
          } else {
            if (controlitem2.options.filed !== undefined) {
              $this.Data.VariableList.push({
                name: controlitem2.options.filed,
                title: controlitem2.title
              })
            }
            childrenitem.Children.push({
              name: controlitem2.model,
              title: controlitem2.title,
              Children: [],
              IsDetail: false
            })
          }
        })
      })
    }
  })

}

FlowData.prototype.Export = function() {
  if (!this.Data) {
    window.parent.postMessage(
      { funname: 'error', msg: '保存的数据为空！' }
    )
    return
  }
  if (this.Data.FlowName == undefined || this.Data.FlowName == '') {
    window.parent.postMessage(
      { funname: 'error', msg: '流程名称不能为空！' }
    )
    return
  }
  let data = {
    flowJson: JSON.stringify(this.Data),
    flowdraw: JSON.stringify(flowObj.SaveDrawJson()),
    flowID: ''
  }
  if (typeof data === 'object') {
    data = JSON.stringify(data, undefined, 4)
  }
  const blob = new Blob([data], { type: 'text/json' })
  const e = document.createEvent('MouseEvents')
  const a = document.createElement('a')
  a.download = this.Data.FlowName + '.json'
  a.href = window.URL.createObjectURL(blob)
  a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
  e.initMouseEvent(
    'click',
    true,
    false,
    window,
    0,
    0,
    0,
    0,
    0,
    false,
    false,
    false,
    false,
    0,
    null
  )
  a.dispatchEvent(e)
}
FlowData.prototype.Import = function() {
  $('#importFile').click()
}
FlowData.prototype.selectFromConfirm = function(rows) {
  if (this.Data.FromID != rows.FID) {
    const frominfo = JSON.parse(rows.fromdesignjson)
    this.UpdateVariable(frominfo, rows.FID)
  }
}
FlowData.prototype.selectUserConfirm = function(userlist, currentfunname,typemode) {
  let usernames = ''
  let userids = ''
  var selectUserlist=[]
  let typemodename=''
  switch (typemode) {
    case 1:typemodename='UserNO'
      break;
    case 2:typemodename='UnitNO'
      break;
    case 3:typemodename='OrganNO'
      break;
    case 4:typemodename='CustomRole'
      break;
  }
  userlist.forEach(ee => {
    selectUserlist.push({no:ee.No,name:ee.Name,type:typemodename})
    usernames = usernames == '' ? ee.Name : usernames + ',' + ee.Name
    userids = userids == '' ? ee.No : userids + ',' + ee.No
  })
  switch (currentfunname) {
    case 'selectStartPerson':
      this.Data.FStartPerson = userids
      this.Data.FStartPersonName = usernames
      break
    case 'selectReadPerson':
      this.Data.FReadPerson = userids
      this.Data.FReadPersonName = usernames
      break
    case 'selectApprover':
      this.selectedNode.FApproverName = usernames
      this.selectedNode.FApprovalObj=selectUserlist
      break
  }
}
FlowData.prototype.LoadVariable = function() {}
Array.prototype.remove = function(val) {
  const index = this.indexOf(val)
  if (index > -1) {
    this.splice(index, 1)
  }
}
